import { defineConfig ,loadEnv} from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import path, { resolve } from 'path';

import vue from '@vitejs/plugin-vue';
import { viteMockServe } from 'vite-plugin-mock'
import { server } from 'typescript';

export default defineConfig(({command,mode})=>{
  // ...
  let env=loadEnv(mode,process.cwd())

  return{
  plugins: [vue(),
    // ...
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    viteMockServe({
     enable: command === 'serve',
      }),
      
  ],
  resolve: {
  // 设置文件./src路径为 @
  alias: [
    {
      find: '@',
      replacement: resolve(__dirname, './src')
    }
  ]
},
server:{
  proxy:{
    [env.VITE_APP_BASE_API ]:{
      target:env.VITE_SERVE,
      changeOrigin:true,
      rewrite:(path)=>path.replace(/^\/api/,'')
    }
  }
        
      }
  }
})